﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

public partial class Them_Hang_Xe2 : System.Web.UI.Page
{
    private string res;
    private string sql;
    protected void Page_Load(object sender, EventArgs e)
    {
        res = Request.QueryString["hx"];
        if (res.Equals("1"))
        {
            lblRes.Text = "Tên Hãng Xe:";
            dongxe.Visible = false;
            doixe.Visible = false;
            sql = "insert into nhasanxuat values (N'" + formatString(txtHangXe.Text) + "')";
        }
        else
        {
            if (res.Equals("2"))
            {
                lblRes.Text = "Tên Dòng Xe:";
                nsx.Visible = false;
                doixe.Visible = false;
                sql = "insert into dongxe values (N'" + formatString(txtHangXe.Text) + "')";
            }
            else
            {
                lblRes.Text = "Tên Đời Xe:";
                nsx.Visible = false;
                dongxe.Visible = false;
                sql = "insert into doixe values(N'" + formatString(txtHangXe.Text) + "')";
            }
        }

    }
    protected void Submit_CLick(object sender, EventArgs e)
    {
        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["hyundaisaigonConnectionString"].ConnectionString);
        connection.Open();
        SqlCommand command = new SqlCommand(sql, connection);
        command.ExecuteNonQuery();
        connection.Close();
        lblxacnhan.Text = "Xử Lí Thành Công";
    }
    private string formatString(string s)
    {
        string result = "";
        try
        {
            string[] arr = s.Split(' ');
            for (int i = 0; i < arr.Length; i++)
            {
                string tmp = arr[i];
                tmp = tmp.ToLower();
                tmp = tmp[0].ToString().ToUpper() + tmp.Substring(1);
                result += tmp;
            }
            return result;
        }
        catch (Exception)
        {
            return s;
        }
    }


}